﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HotShot.Entities;
using HotShot.Service.Entities;

namespace HotShot.Service.BusinessLogic
{
    public class EntityStoreLogic
    {
        public static EntityStoreLogic Current = new EntityStoreLogic();

        public Dictionary<string, StorageEntity> storageHash = new Dictionary<string, StorageEntity>();

        public void Initialize()
        {
        }

        public void Put(StorageEntity item) 
        {
            if (storageHash.ContainsKey(item.Key))
            {
                if (storageHash[item.Key].Ticks >= item.Ticks)
                    throw new ApplicationException("Concurrency");
            }

            storageHash[item.Key] = item;
        }

        public StorageEntity Get(string key)
        {
            if (!storageHash.ContainsKey(key))
                throw new ApplicationException("Key not found");

            return storageHash[key];
        }
    }
}
